<?php

namespace App\Criteria;

use Prettus\Repository\Contracts\CriteriaInterface;
use Prettus\Repository\Contracts\RepositoryInterface;
use Zend\Diactoros\Request;

/**
 * Class RecordTimeCriteria
 * @package namespace App\Criteria;
 */
class CarAuthTimeCriteria implements CriteriaInterface
{
    /**
     * Apply criteria in query repository
     *
     * @param                     $model
     * @param RepositoryInterface $repository
     *
     * @return mixed
     */
    public function apply($model, RepositoryInterface $repository)
    {
        $data = _request(request('search'));
        if(isset($data['start_time'])) {

            $model = $model-> where('created_at','>=',$data['start_time']);
        }

        if(isset($data['end_time'])) {

            $model = $model-> where('created_at','<',$data['end_time']);
        }

        return $model;
    }
}
